package spring.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import spring.dao.BookDao;
import spring.service.BookService;

/**
 * @author Yancy xiao
 * @create 2023-01-01 19:08
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
//    @Transactional(
//            readOnly = false,
//            timeout = 3,
//            noRollbackFor = {ArithmeticException.class},
//            isolation = Isolation.DEFAULT,
//            propagation = Propagation.REQUIRES_NEW
//    )
    public void buyBook(Integer userId, Integer bookId) {
        //查价格
        Integer price = bookDao.getPriceByBookId(bookId);
        //更新图书库存
        bookDao.updateStock(bookId);
        //更新用户的余额
        bookDao.updateBalance(userId, price);
    }
}